package com.mycompany.javasockettcp01;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 *
 * @author jian.zhou
 */
public class TCPClient {

    public static void main(String[] args) throws IOException {
        try (
                Socket socket = new Socket("192.168.205.122", 8888);) {
            OutputStream os = socket.getOutputStream();
            byte[] text = "你好服务器".getBytes();
            os.write(text);

            InputStream is = socket.getInputStream();
            int len = is.read(text);
            System.out.println(new String(text, 0, len));
        }catch (Exception e){
            System.out.println("连接异常");
        }
    }
}
